package main

import (
	"fmt"
	"log"
	"net/http"

	"cache/day3/geecache"
)

var db = map[string]string{
	"ZhangSan": "123",
	"LiSi":     "456",
	"WangWu":   "789",
}

func main() {
	geecache.NewGroup("source", 2<<10, geecache.GetterFunc(func(key string) ([]byte, error) {
		log.Println("[SlowDB] search key")
		if v, ok := db[key]; ok {
			return []byte(v), nil
		}

		return nil, fmt.Errorf("%s not exist", key)
	}))

	addr := "localhost:8080"
	peers := geecache.NewHTTPPool(addr)
	log.Println("geecache is running at", addr)
	http.ListenAndServe(addr, peers)
}
